﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Data.Entity;
using DataContextLayer;
using EF5;

namespace DatabaseTestConsole
{
	class Program
	{
        static void Main(string[] args)
		{

			/* Creating a seed
			 * Setting up DB initilizer
			 */
			//Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DclContext>());
			//Database.SetInitializer(new Ef5Init());


			//using (var context = new DclContext() )
			//{

				//var firstUser = new User
				//{ UserName = "Lou", UserPassword = "evan12", UserEmail = "my@email.com", UserPasswordReset = false };

				//var firstAchievment = new Achievment
				//{UserId = 1, AchievmentTitle = "Creator!", AchievmentDescription = "Created the new EF5 DB for this application" };

				//context.Users.Add(firstUser);

				/* 
				 * This failed find out why.
				 */

				//firstUser.Achievments.Add(firstAchievment);

				//context.Achievments.Add(firstAchievment);

				//context.SaveChanges();

				/* 
				 * Validation testing useing DB side
				 */

				//var newUser = new User
				//{
				//    UserName = "te",
				//    UserPassword = "tested",
				//    UserEmail = "test@email.com",
				//    UserPasswordReset = false
				//};

				//context.Users.Add(newUser);

				//var validationErrors = context.GetValidationErrors()
				//    .Where(vr => !vr.IsValid).SelectMany(vr => vr.ValidationErrors);

				//foreach (var dbValidationError in validationErrors)
				//{
				//    Console.WriteLine(dbValidationError.ErrorMessage);
				//}

				//context.SaveChanges();

				/* 
				 *  Loading related content indirectly
				 */

				//var userOne = context.Users.Include(p=>p.Achievments).ToList();

				//foreach (User user in userOne)
				//{
				//    Console.WriteLine(user.Achievments.ToList());
				//    var test = user.Achievments.ToList();
				//    foreach (var user1 in test)
				//    {
				//        Console.Write(user1.AchievmentTitle);
				//    }
				//}

			//Console.ReadKey();


			//}

			    /* 
				 * XML Testing
				 */

			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Regular xml>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");


			//var doc = XElement.Load("testingxml.xml");

			//var query = from e in doc.Elements("TutorialSteps")
			//            select e;


			//var MyList = query.ToList();

			//foreach (var element in query)
			//{
			//    Console.WriteLine(element);
			//}

			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Namespace.xml>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");


			//doc = XElement.Load("testingxmlNS.xml");

			//query = from e in doc.Elements("{c#:tutorials}TutorialStep")
			//        select e;

			//foreach (var element in query)
			//{
			//    Console.WriteLine(element.Attribute("step").Value+" : "+element.Value);
			//    //Console.WriteLine(element.Attribute("step").Value);
			//}
			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@sum of steps>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");

			//var sum = query.Sum(e => int.Parse(e.Attribute("step").Value));

			//Console.WriteLine(sum);

			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Namespace aware query>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");

			//const string tutorialNs = "c#:tutorials";

			//query = from ele in doc.Elements(XName.Get("TutorialStep", tutorialNs))
			//        let p = ele.Parent
			//        where p.Name == XName.Get("Tutorial", tutorialNs)
			//              && p.Parent == null
			//        select ele;
			//foreach (var ele in query)
			//{
			//    Console.WriteLine(ele.Attribute("step").Value + " : " + ele.Value);
			//}


			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Zero base check>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");
			//Console.WriteLine(@"");
			//Console.WriteLine(@"Pick a number 0-4");

			//var checking = query.ElementAt(int.Parse(Console.ReadLine()));

			

			//Console.WriteLine(checking.Attribute("step").Value +" : "+checking.Value);

			//Console.WriteLine(@"Now pick a number 1-5");

			//checking = query.ElementAt(int.Parse(Console.ReadLine()) - 1);

			//Console.WriteLine(checking.Attribute("step").Value + " : " + checking.Value);



			///*
			// * 
			// * Xpath node types notes
			// * 
			// <!-- example --> @This is a comment node
			// <tns:Tutorial xmlns:tns="c#:tutorials"> @This is a Root Node
			//    <TutorialStep step="1">creating the if</TutorialStep>@ Element node
			//    <TutorialStep step="2" <-@This is attribute Node  >creating the condition</TutorialStep>
			//    <TutorialStep step="3">evaluating the condition <-@This is Text Node </TutorialStep>
			//    <TutorialStep step="4">the body</TutorialStep>
			//    <TutorialStep step="5">finishing up</TutorialStep>	
			// </tns:Tutorial>
			// * 
			// * 
			// * <?ship-from stock room?>@ proccesing instruction node
			// * 
			// */

			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Xpath tests>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");
			//Console.WriteLine(@"");


			//doc = XElement.Load("testingxmlNSprefix.xml");

			//query = doc.GetElementUsingXpath("/self::a:Tutorial/a:TutorialStep", "a:c#:tutorials");

			//foreach (var element in query)
			//{
			//    Console.WriteLine(element.Attribute("step").Value + " : " + element.Value);
			//}

			//Console.WriteLine(@"");
			//Console.WriteLine(@"");
			//Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			//Console.WriteLine(@"<<<<<<<<@Xpath tests>>>>>>>>>>>");
			//Console.WriteLine(@"<<<<<<<<@Sum threw xpath@>>>>>>>>>>>");
			//Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
			//Console.WriteLine(@"");
			//Console.WriteLine(@"");

			//sum = query.Sum(e => int.Parse(e.Attribute("step").Value));

			//Console.WriteLine(sum);


            //Console.WriteLine(@"");
            //Console.WriteLine(@"");
            //Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            //Console.WriteLine(@"<<<<<<<<@XML to List>>>>>>>>>>>");
            //Console.WriteLine(@"<<<<<<<<@count test@>>>>>>>>>>>");
            //Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            //Console.WriteLine(@"");
            //Console.WriteLine(@"");


            //var doc = XElement.Load("C#_Output_tutorial.xml.xml");

            //var query = from e in doc.Elements("TutorialStep")
            //            select e;


            //var MyList = query.ToList();

            ///*  
            // * XML To list now manipulate list for items
            // */

            //Console.WriteLine(MyList.Count());


            ///*  
            // * EF5 To list now manipulate list for Users
            // */

            //Console.WriteLine(@"");
            //Console.WriteLine(@"");
            //Console.WriteLine(@"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
            //Console.WriteLine(@"<<<<<<<<@EF5to List>>>>>>>>>>>");
            //Console.WriteLine(@"<<<<<<<<@count test@>>>>>>>>>>>");
            //Console.WriteLine(@">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
            //Console.WriteLine(@"");
            //Console.WriteLine(@"");

            //var context = new DclContext(); 
			
            //var	queryEF = from t in context.Users
            //            select t;

            //List<User> UserList = queryEF.ToList();

            //Console.WriteLine(UserList.Count());

            //foreach (var user in UserList)
            //{
            //    Console.WriteLine(user.UserName);
            //}

            ////Console.WriteLine(UserList.ElementAt(0).UserName);

			

			
			


            //Console.ReadKey();


            Console.WriteLine("test");
            
		}
	}
}
